/*
 * PauseDownloadAction.java
 *
 * Copyright 2007, 2008 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Lailaps.
 *
 * Tiberiumlabs Lailaps is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Lailaps is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.tiberiumlabs.lailaps.actions.list;

import java.util.Arrays;
import org.tiberiumlabs.lailaps.actions.AbstractElementAction;
import org.tiberiumlabs.lailaps.list.DownloadItem;
import org.tiberiumlabs.lailaps.list.StatusConstants;
import org.tiberiumlabs.lailaps.resources.ImageLoader;

/**
 *
 * @author <a href="paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
public class PauseDownloadAction extends AbstractElementAction implements StatusConstants {
    
    /** Creates a new instance of PauseDownloadAction */
    public PauseDownloadAction() {
        putValue(NAME, bundle.getString("list.pause.name"));
        putValue(SHORT_DESCRIPTION, bundle.getString("list.pause.short"));
        putValue(LONG_DESCRIPTION, bundle.getString("list.pause.long"));
        putValue(LARGE_ICON_KEY, ImageLoader.getPuseImage());
        putValue(SMALL_ICON, ImageLoader.getMenuPauseIcon());
    }
    
    @Override
    protected void performElementAction(int[] rows) {
        
        Arrays.sort(rows);
        
        for (int i = rows.length-1; i >= 0; i--) {
            DownloadItem item = model.getItem(rows[i]);
            switch (item.getStatus()) {
                case STOPPED:
                case COMPLETED:
                case ERROR:
                case PAUSED:
                    continue;
                default:
                    threadsMap.get(item).pause();
            }
        }
    }
    
}
